package cn.songit.repository;

import cn.songit.entity.Demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

@Repository("demoRepository2")
public class DemoRepositoryJdbcTemplate {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public Demo getById(Integer id){
        String sql = "select * from Demo where id=?";
        RowMapper<Demo> mapper = new BeanPropertyRowMapper<>(Demo.class);
        return jdbcTemplate.queryForObject(sql,mapper,id);
    }

}
